package com.yupi.springbootinit.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**
 * @Author xingyu Xue
 * @Date 2023/11/24 15:19
 *
 *
 * @ConfigurationProperties(prefix = "spring.redis")  可以读取application.yml中的配置文件
 */

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {
    private Integer database;

    private String host;

    private Integer port;

    private String password;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
//        config.useSingleServer().setAddress("redis://43.138.168.228:6379").setDatabase(database)
//                .setPassword("123321");


        config.useSingleServer()
                .setDatabase(database)
                .setAddress("redis://" + host + ":" + port).setPassword(password);
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }




}
